﻿// Decompiled with JetBrains decompiler
// Type: System.Web.Razor.Parser.ParserHelpers
// Assembly: System.Web.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// MVID: 682513D6-F37E-48AC-9909-F3EE103CFF14
// Assembly location: D:\Project\Idea\无人机外网\uav\客户端工程\排查工具\bin\Release\System.Web.Razor.dll

using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace System.Web.Razor.Parser
{
  /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Provides helper methods for the parser.</summary>
  public static class ParserHelpers
  {
    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified value is a newline.</summary>
    /// <returns>true if the specified character is a newline; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsNewLine(char value) => value == '\r' || value == '\n' || (value == '\u0085' || value == '\u2028') || value == '\u2029';

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified value is a newline.</summary>
    /// <returns>true if the specified character is a newline; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsNewLine(string value) => value.Length == 1 && ParserHelpers.IsNewLine(value[0]) || string.Equals(value, "\r\n", StringComparison.Ordinal);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is a whitespace.</summary>
    /// <returns>true if the specified character value is a whitespace; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsWhitespace(char value) => value == ' ' || value == '\f' || (value == '\t' || value == '\v') || char.GetUnicodeCategory(value) == UnicodeCategory.SpaceSeparator;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is a whitespace or newline.</summary>
    /// <returns>true if the specified character value is a whitespace or newline; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsWhitespaceOrNewLine(char value) => ParserHelpers.IsWhitespace(value) || ParserHelpers.IsNewLine(value);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified string value is an identifier.</summary>
    /// <returns>true if the specified string value is an identifier; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsIdentifier(string value) => ParserHelpers.IsIdentifier(value, true);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified string value is an identifier.</summary>
    /// <returns>true if the specified string value is an identifier; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    /// <param name="requireIdentifierStart">true to require that the identifier starts with a letter or underscore (_); otherwise, false.</param>
    public static bool IsIdentifier(string value, bool requireIdentifierStart)
    {
      IEnumerable<char> source = (IEnumerable<char>) value;
      if (requireIdentifierStart)
        source = source.Skip<char>(1);
      return (!requireIdentifierStart || ParserHelpers.IsIdentifierStart(value[0])) && source.All<char>(new Func<char, bool>(ParserHelpers.IsIdentifierPart));
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is a hexadecimal digit number.</summary>
    /// <returns>true if the specified character is a hexadecimal digit number; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsHexDigit(char value)
    {
      if (value >= '0' && value <= '9' || value >= 'A' && value <= 'F')
        return true;
      return value >= 'a' && value <= 'f';
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is valid for use as start character of an identifier.</summary>
    /// <returns>true if the specified character value is valid for use as start character of an identifier; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsIdentifierStart(char value) => value == '_' || ParserHelpers.IsLetter(value);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is valid for use in identifier.</summary>
    /// <returns>true if the specified character is valid for use in identifier; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsIdentifierPart(char value) => ParserHelpers.IsLetter(value) || ParserHelpers.IsDecimalDigit(value) || (ParserHelpers.IsConnecting(value) || ParserHelpers.IsCombining(value)) || ParserHelpers.IsFormatting(value);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is a terminating character token.</summary>
    /// <returns>true if the specified character value is a terminating character token; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsTerminatingCharToken(char value) => ParserHelpers.IsNewLine(value) || value == '\'';

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is a terminating quoted string.</summary>
    /// <returns>true if the specified character value is a terminating quoted string; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsTerminatingQuotedStringToken(char value) => ParserHelpers.IsNewLine(value) || value == '"';

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is a decimal digit number.</summary>
    /// <returns>true if the specified character value is a decimal digit number; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsDecimalDigit(char value) => char.GetUnicodeCategory(value) == UnicodeCategory.DecimalDigitNumber;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is a letter or a decimal digit number.</summary>
    /// <returns>true if the specified character is a letter or a decimal digit number; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsLetterOrDecimalDigit(char value) => ParserHelpers.IsLetter(value) || ParserHelpers.IsDecimalDigit(value);

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is a letter.</summary>
    /// <returns>true if the specified character is a letter; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsLetter(char value)
    {
      UnicodeCategory unicodeCategory = char.GetUnicodeCategory(value);
      switch (unicodeCategory)
      {
        case UnicodeCategory.UppercaseLetter:
        case UnicodeCategory.LowercaseLetter:
        case UnicodeCategory.TitlecaseLetter:
        case UnicodeCategory.ModifierLetter:
        case UnicodeCategory.OtherLetter:
          return true;
        default:
          return unicodeCategory == UnicodeCategory.LetterNumber;
      }
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is used for formatting text layout or formatting text operation.</summary>
    /// <returns>true if the specified character value is used for formatting text layout or formatting text operation.; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsFormatting(char value) => char.GetUnicodeCategory(value) == UnicodeCategory.Format;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is a spacing combining mark or a non-spacing mark.</summary>
    /// <returns>true if the specified character value is a spacing combining mark or a non-spacing mark; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsCombining(char value)
    {
      UnicodeCategory unicodeCategory = char.GetUnicodeCategory(value);
      return unicodeCategory == UnicodeCategory.SpacingCombiningMark || unicodeCategory == UnicodeCategory.NonSpacingMark;
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is a connector punctuation.</summary>
    /// <returns>true if the specified character value is a connector punctuation; otherwise, false.</returns>
    /// <param name="value">The value to check.</param>
    public static bool IsConnecting(char value) => char.GetUnicodeCategory(value) == UnicodeCategory.ConnectorPunctuation;

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Sanitizes the specified input name to conform as a valid value for class name.</summary>
    /// <returns>The sanitized class name.</returns>
    /// <param name="inputName">The value to check.</param>
    public static string SanitizeClassName(string inputName)
    {
      if (!ParserHelpers.IsIdentifierStart(inputName[0]) && ParserHelpers.IsIdentifierPart(inputName[0]))
        inputName = "_" + inputName;
      return new string(inputName.Select<char, char>((Func<char, char>) (value => !ParserHelpers.IsIdentifierPart(value) ? '_' : value)).ToArray<char>());
    }

    /// <summary>This type/member supports the .NET Framework infrastructure and is not intended to be used directly from your code. Determines whether the specified character value is valid for use in email address.</summary>
    /// <returns>true if the specified character value is valid for use in email address; otherwise, false.</returns>
    /// <param name="character">The value to check.</param>
    public static bool IsEmailPart(char character) => char.IsLetter(character) || char.IsDigit(character) || character == '_';
  }
}
